package month1;

public class FlattenBinaryTreeToLinkedList114_05 {
    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(new Integer[]{});
        System.out.println(treeNode);
        flatten(treeNode);
        System.out.println(treeNode);
    }

    /**
     * 递归吧
     * @param root
     */
    static void flatten(TreeNode root) {
        if (root == null) {
            return;
        }
        flatten(root.left);
        flatten(root.right);
        if (root.left != null) {
            TreeNode node = root.left;
            while (node.right != null) {
                node = node.right;
            }
            node.right = root.right;
            root.right = root.left;
            root.left = null;
        }
    }
}
